
//
// 110614 - AH - Created.
//

package org.soekrat.gui.swing.resource;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.TreeCellEditor;

import org.soekrat.engine.SoekratName;
import org.soekrat.engine.mine.Resource;

/**
 * <p>
 *   {@link TreeCellEditor} for
 *   {@link JTree} used in
 *   {@link ResourceTreePanel}. 
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class ResourceTreeCellEditor extends DefaultTreeCellEditor 
{
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param tree View.
   */
  public ResourceTreeCellEditor(JTree tree)
  {
    super(tree, ResourceTreeCellRenderer.INSTANCE);
  }

  // Specified in DefaultTreeCellEditor.
  public Component getTreeCellEditorComponent(JTree tree, Object val,
    boolean isSelected, boolean expanded, boolean leaf, int row)
  {
    String text=val.toString();
    
    if (val instanceof Resource)
    {
      text=((Resource)val).getSoekratName().toString();  
    }
    else if (val instanceof SoekratName)
    {
      text=((SoekratName)val).toString();
    }
    
    return super.getTreeCellEditorComponent(tree, text, isSelected, expanded, 
      leaf, row);
  }
  
}
